package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    // 新增菜品
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);
    // 分页查询菜品
    List<Dish> pageQuery(DishPageQueryDTO dishPageQueryDTO);
    // 批量删除菜品
    void delete(List<Long> ids);
    // 启用停售菜品
    @Update("update dish set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);
    // 根据id查询菜品
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);
    // 修改菜品
    @AutoFill(OperationType.UPDATE)
    void updateById(Dish dish);
    // 根据分类id查询菜品
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> list(Long categoryId);
    // 根据状态查询菜品
    @Select("select * from dish where status = #{status} and category_id = #{categoryId}")
    List<Dish> listByStatus(Dish dish);
    // 根据分类id查询菜品数量
    @Select("select count(id) from dish where category_id = #{id}")
    int countByCategoryId(Long id);
    // 根据菜品id查询菜品状态
    @Select("select status from dish where id = #{dishId}")
    Long getBystatus(Long dishId);
    // 根据菜品id查询菜品
    Dish  getBydishId(Long dishId);
    //根据条件统计菜品数量
    Integer countByMap(Map map);
}
